package view.mediator
{
	import controllers.commands.ClearMapCommand;
	import controllers.managers.UIInstanceManager;
	
	import event.MultiDeviceEvent;
	
	import flash.events.MouseEvent;
	
	import model.context.DeviceMonitorContext;
	import model.context.base.IContext;
	
	import mx.core.FlexGlobals;
	import mx.core.UIComponent;
	
	import utils.UIUtil;
	
	import view.ListPanel;
	import view.LoginPanel;
	import view.mediator.base.IMediator;
	import view.panel.DeviceSelectionPanel;
	import view.panel.MultiDeviceMonitor;
	
	public class LoginMediator implements IMediator
	{
		public static var NAME : String = "LoginMediator.as";
		private var loginPanel : LoginPanel = null;
		
		public function LoginMediator()
		{
		}
		
		public function setView(view:UIComponent):void
		{
			loginPanel = LoginPanel(view);
			initEvents();
		}
		
		public function initEvents():void
		{
			loginPanel.addEventListener(MultiDeviceEvent.MULTI_DEVICE_LOC, onInMultiDevHandler);
		}
		
		/**
		 *  进入多设备定位
		 **/
		private function onInMultiDevHandler(evt:MultiDeviceEvent):void
		{
			var selectorPanel:DeviceSelectionPanel = DeviceSelectionPanel(UIInstanceManager.getUI( DeviceSelectionPanel.NAME));
			var deviceMonitorPanel:MultiDeviceMonitor = MultiDeviceMonitor(UIInstanceManager.getUI( MultiDeviceMonitor.NAME));
			var listPanel:ListPanel = ListPanel(UIInstanceManager.getUI(ListPanel.NAME));
			
			if (selectorPanel !=null && deviceMonitorPanel != null)
			{
				selectorPanel.visible = true;
				var map:Maper = Maper(FlexGlobals.topLevelApplication);
				UIUtil.setToTop(selectorPanel, map);
				
				deviceMonitorPanel.visible=false;
				//进入设备选择状态
				listPanel.setHomeState();
				new ClearMapCommand().execute();
			}
		}
		
		public function setContext(context:IContext):void
		{
		}
	}
}